<?php

/*
 * Smarty plugin
 * ------------------------------------------------------------
 * Type:       modifier
 * Name:       quantifier
 * Purpose:    Zwraca liczby z poprawnymi polskimi liczebnikami
 * ------------------------------------------------------------
 */
function smarty_modifier_quantifier($number, $type = 'wynik') {
	$out = array(
		'wynik' => array(
			1 => 'wynik',
			2 => 'wyniki',
			3 => 'wyników'
		)
	);	
	$i = 3;
	if($number == 1) {
		$i = 1;
	} else {
		$n1 = $number%100;
		$n2 = $number%10;
		if (($n1 != 12 && $n1 != 13 && $n1 != 14) && ($n2 == 2 || $n2 == 3 || $n2 == 4)) {
			$i = 2;
		} else {
			$i = 3;
		}
	}
	return $number . ' ' . $out[$type][$i]; 
}
?>